#include "linkfabric/Crypto.hpp"
#include <algorithm>
#include <cstdint>

using namespace linkfabric;

std::vector<uint8_t> Crypto::encrypt(const std::vector<uint8_t>& data, const std::string& key) {
    std::vector<uint8_t> out = data;
    for (size_t i = 0; i < out.size(); ++i) {
        out[i] ^= static_cast<uint8_t>(key[i % key.size()]);
    }
    return out;
}

std::vector<uint8_t> Crypto::decrypt(const std::vector<uint8_t>& data, const std::string& key) {
    return encrypt(data, key);
}